﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Data;
using System.Reflection;
using System.Windows;
using Cinch;
using Fluent;
using SLS.Presentation;
using MEFedMVVM.Common;
using MEFedMVVM.ViewModelLocator;
using SLS.Base;
using SLS.Controls;
using SLS.Core.Workspace;
using SLS.Document;
using SLS.ExClassLib.Database;
using SLS.ExClassLib.Events;
using SLS.ExClassLib.Loc;
using SLS.ExClassLib.MVVM;
namespace SLS.Client
{
    /// <summary>
    /// This ViewModel demonstrates how to use WorkSpaces and Menus. You will
    /// need to look in the MainWindow.xaml and also the AppStyles.xaml ResourceDictionary
    /// to see how the Styles are used to tie up with this ViewModel
    /// </summary>
    [ExportViewModel("MainWindowViewModel")]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class MainWindowViewModel : ViewModelBase
    {
        #region Data
        private bool showContextMenu = false;
        private IViewAwareStatus viewAwareStatusService;
        private IMessageBoxService messageBoxService;
        private IMenuService menuservice;
        #endregion

        #region Ctor
        [ImportingConstructor]
        public MainWindowViewModel(
            IViewAwareStatus viewAwareStatusService, 
            IMessageBoxService messageBoxService,
            IMenuService menuservice)
        {
            try
            {
                DocumentManagement.Instance.CenterDocuments = this;
                this.viewAwareStatusService = viewAwareStatusService;
                this.viewAwareStatusService.ViewLoaded += ViewAwareStatusService_ViewLoaded;
                this.messageBoxService = messageBoxService;
                this.menuservice = menuservice;
                ViewDataSet = new DataModel(); 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
 
        #endregion

        #region Private Methods
        /// <summary>
        /// Creates and returns the menu items
        /// </summary> 
        private void ViewAwareStatusService_ViewLoaded()
        {
            if (Designer.IsInDesignMode)
                return;
            string doctype = "GeneralGUI";
            ActivateReportByDocType(doctype);
        }
        public void ActivateReportByDocType(string doctype)
        {
            DocumentManagement.Instance.LoadAssembly("GeneralGUI");
            String imagePath = @"/SLCLIENT;component/Resources/Images/128x128/file/EveryRecord.png";
            WorkspaceData wks = new WorkspaceData(imagePath,
                "DocumentCenter", imagePath, "DocumentCenter", true);
            Documents.Add(wks);
            SetActiveWorkspace(wks);
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// Returns the bindbable Main Window options
        /// </summary>
        public  List<WPFMenuItem> M0
        {
            get
            {
                return menuservice.GetChildMenu("0");
            }
        } 
        /// <summary>
        /// ShowContextMenu
        /// </summary>
        static PropertyChangedEventArgs showContextMenuArgs =
            ObservableHelper.CreateArgs<MainWindowViewModel>(x => x.ShowContextMenu);

        public bool ShowContextMenu
        {
            get { return showContextMenu; }
            private set
            {
                showContextMenu = value;
                NotifyPropertyChanged(showContextMenuArgs);
            }
        }
        #endregion

    }

}
